package com.gwtgeo.ui.client.mvp.windowsmanager;

import java.util.Map;

import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;

import net.customware.gwt.presenter.client.EventBus;
import net.customware.gwt.presenter.client.widget.WidgetPresenter;

public abstract class WindowedPresenter<D extends WindowedDisplay> extends
		WidgetPresenter<D> implements RecoversWinData {

	public WindowedPresenter(D display, EventBus eventBus) {
		super(display, eventBus);
	}

	public abstract void init(Map<String, Object> params);

	public abstract WindowTypeEnum getType();

	@Override
	public void retrieveWinData(WindowTypeEnum source, Map<String, Object> data) {
	}

	@Override
	protected void onBind() {
		this.registerHandler(display.getHeaderClicks().get(
				WindowedDisplay.CLOSE_HEADER).addClickHandler(
				new ClickHandler() {

					@Override
					public void onClick(ClickEvent event) {
						onWindowClose();
					}
				}));
		this.registerHandler(display.getHeaderClicks().get(
				WindowedDisplay.MINIMIZE_HEADER).addClickHandler(
				new ClickHandler() {

					@Override
					public void onClick(ClickEvent event) {
						onWindowMinimize();
					}
				}));
	}

	protected void onWindowClose(){
		this.display.hide();
		this.unbind();
	}

	protected void onWindowMinimize(){
		this.display.hide();
	}

	public void show() {
		display.show();
	}

	public void hide() {
		display.hide();
	}

}
